home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96a.txt
/
000022_icon-group-sender _Mon Jan 22 16:04:35 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1996-09-05
|
3KB
Received: by cheltenham.cs.arizona.edu; Mon, 22 Jan 1996 16:25:25 MST
From: Nick Williams <nmw@styx.ios.com>
Message-Id: <199601222104.QAA03988@styx.ios.com>
Subject: Hacking icon src; adding features
To: icon-group@cs.arizona.edu
Date: Mon, 22 Jan 1996 16:04:35 -0500 (EST)
X-Mailer: ELM [version 2.4 PL23]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 2786
Errors-To: icon-group-errors@cs.arizona.edu
Status: O
I'm not a member of the Icon Project; just an Icon enthusiast. I like
the language a lot, but there's a handful of features I wish were there
that aren't, in particular I wish it had closures. In the past, when
I've brought this up, I was told that this wasn't going to be considered
soon, besides which co-expressions provide a rough sort of closures.
So I've been looking lately to implement closures myself. After much
consideration, the simplest way to do this, with the least amount of
work needed is to modify the interpreter to load and save the values of
closed local variables in a list a pointer to which is stored in the
b_proc structure for each procedure; a new function (closeproc()) is
used to create new copies of Icon procedure some, or all of whose local
variables have persistent values. Those of you who are familiar with
Lisp probably understand what I am talking about, for those who don't,
the best way to describe this feature is that with it you can make
copies of a procedure that has static variables such that each copy has
_different_ static variables.
Here's how I'm going about implementing this:
- add a new field to the b_proc structure: struct descrip closedvars
which should normally be &null or point to an Icon list.
- fix invoke.r:invoke() so that when it's done manipulating the
stack it copies the stored values of closed variables into the
corresponding local variables on the stack. The list pointed
to by the new closedvars field of b_proc consists of
descriptor pairs, where the first descriptor is an integer
representing an index into the local variable array, and the
second descriptor is the stored value for that local
variable.
- fix interp.r:interp() so that the values of closed local
variables are copied back into the closedvars list whenever a
procedure with closed variables returns or fails.
- fix icont/lcode.c:lemitproc() and icont/lcode.c:gentables() so
the closedvars field of b_proc structures is initialized to
&null.
- fix the firstd[] and other tables in rmemmgt.r.
- fix init.r (the B_IProc(n) stuff).
- add closeproc() to runtime/fmisc.r. This function should take
an Icon procedure as its first argument, followed by
variable_name:initial_value pairs. A more Lisp-like procedure
closing function can be built ontop of this.
I would much rather do the above for static procedure variables instead
of local dynamic variables, but that would require much larger changes.
I've got most of the above complete, and at least I have something that
compiles (I have yet to test it). But since I'm have little knowledge of
the implementation of Icon, I must ask wether there is any other place I
must look in and edit to make this work.
Any comments? Ideas?
Nick